home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Chat & Communication
/
Digsby build 37
/
digsby_setup.exe
/
lib
/
dns
/
query.pyo
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2008-10-13
|
8KB
|
337 lines
# Source Generated with Decompyle++
# File: in.pyo (Python 2.5)
from __future__ import generators
import errno
import select
import socket
import struct
import sys
import time
import dns.exception as dns
import dns.inet as dns
import dns.name as dns
import dns.message as dns
import dns.rdataclass as dns
import dns.rdatatype as dns
class UnexpectedSource(dns.exception.DNSException):
pass
class BadResponse(dns.exception.FormError):
pass
def _compute_expiration(timeout):
if timeout is None:
return None
else:
return time.time() + timeout
def _wait_for(ir, iw, ix, expiration):
done = False
check_count = 0
while not done:
check_count += 1
if check_count > 5000:
print >>sys.stderr, 'DNS LOOP? dns.query._wait_for has run %d times' % check_count
if expiration is None:
timeout = None
else:
timeout = expiration - time.time()
if timeout <= 0:
raise dns.exception.Timeout
try:
if timeout is None:
(r, w, x) = select.select(ir, iw, ix)
else:
(r, w, x) = select.select(ir, iw, ix, timeout)
except select.error:
e = None
if e.args[0] != errno.EINTR:
raise e
except:
e.args[0] != errno.EINTR
done = True
if len(r) == 0 and len(w) == 0 and len(x) == 0:
raise dns.exception.Timeout
continue
def _wait_for_readable(s, expiration):
_wait_for([
s], [], [
s], expiration)
def _wait_for_writable(s, expiration):
_wait_for([], [
s], [
s], expiration)
def udp(q, where, timeout = None, port = 53, af = None, source = None, source_port = 0, ignore_unexpected = False):
wire = q.to_wire()
if af is None:
try:
af = dns.inet.af_for_address(where)
af = dns.inet.AF_INET
if af == dns.inet.AF_INET:
destination = (where, port)
if source is not None:
source = (source, source_port)
elif af == dns.inet.AF_INET6:
destination = (where, port, 0, 0)
if source is not None:
source = (source, source_port, 0, 0)
s = socket.socket(af, socket.SOCK_DGRAM, 0)
try:
expiration = _compute_expiration(timeout)
s.setblocking(0)
if source is not None:
s.bind(source)
_wait_for_writable(s, expiration)
s.sendto(wire, destination)
check_count = 0
while None:
check_count += 1
if check_count > 5000:
print >>sys.stderr, 'DNS LOOP? dns.query.udp loop has run %d times' % check_count
(wire, from_address) = s.recvfrom(65535)
if (from_address == destination or dns.inet.is_multicast(where)) and from_address[1] == destination[1]:
break
if not ignore_unexpected:
raise UnexpectedSource, 'got a response from %s instead of %s' % (from_address, destination)
continue
s.close()
r = dns.message.from_wire(wire, keyring = q.keyring, request_mac = q.mac)
if not q.is_response(r):
raise BadResponse
return r
def _net_read(sock, count, expiration):
s = ''
check_count = 0
while count > 0:
check_count += 1
if check_count > 5000:
print >>sys.stderr, 'DNS LOOP? dns.query._net_read loop has run %d times' % check_count
_wait_for_readable(sock, expiration)
n = sock.recv(count)
if n == '':
raise EOFError
count = count - len(n)
s = s + n
return s
def _net_write(sock, data, expiration):
current = 0
l = len(data)
check_count = 0
while current < l:
check_count += 1
if check_count > 5000:
print >>sys.stderr, 'DNS LOOP? dns.query._net_write loop has run %d times' % check_count
_wait_for_writable(sock, expiration)
current += sock.send(data[current:])
def _connect(s, address):
try:
s.connect(address)
except socket.error:
(ty, v) = sys.exc_info()[:2]
if v[0] != errno.EINPROGRESS and v[0] != errno.EWOULDBLOCK and v[0] != errno.EALREADY:
raise ty, v
except:
v[0] != errno.EALREADY
def tcp(q, where, timeout = None, port = 53, af = None, source = None, source_port = 0):
wire = q.to_wire()
if af is None:
try:
af = dns.inet.af_for_address(where)
af = dns.inet.AF_INET
if af == dns.inet.AF_INET:
destination = (where, port)
if source is not None:
source = (source, source_port)
elif af == dns.inet.AF_INET6:
destination = (where, port, 0, 0)
if source is not None:
source = (source, source_port, 0, 0)
s = socket.socket(af, socket.SOCK_STREAM, 0)
try:
expiration = _compute_expiration(timeout)
s.setblocking(0)
if source is not None:
s.bind(source)
_connect(s, destination)
l = len(wire)
tcpmsg = struct.pack('!H', l) + wire
_net_write(s, tcpmsg, expiration)
ldata = _net_read(s, 2, expiration)
(l,) = struct.unpack('!H', ldata)
wire = _net_read(s, l, expiration)
finally:
s.close()
r = dns.message.from_wire(wire, keyring = q.keyring, request_mac = q.mac)
if not q.is_response(r):
raise BadResponse
return r
def xfr(where, zone, rdtype = dns.rdatatype.AXFR, rdclass = dns.rdataclass.IN, timeout = None, port = 53, keyring = None, keyname = None, relativize = True, af = None, lifetime = None, source = None, source_port = 0, serial = 0):
if isinstance(zone, (str, unicode)):
zone = dns.name.from_text(zone)
q = dns.message.make_query(zone, rdtype, rdclass)
if rdtype == dns.rdatatype.IXFR:
rrset = dns.rrset.from_text(zone, 0, 'IN', 'SOA', '. . %u 0 0 0 0' % serial)
q.authority.append(rrset)
if keyring is not None:
q.use_tsig(keyring, keyname)
wire = q.to_wire()
if af is None:
try:
af = dns.inet.af_for_address(where)
af = dns.inet.AF_INET
if af == dns.inet.AF_INET:
destination = (where, port)
if source is not None:
source = (source, source_port)
elif af == dns.inet.AF_INET6:
destination = (where, port, 0, 0)
if source is not None:
source = (source, source_port, 0, 0)
s = socket.socket(af, socket.SOCK_STREAM, 0)
if source is not None:
s.bind(source)
expiration = _compute_expiration(lifetime)
_connect(s, destination)
l = len(wire)
tcpmsg = struct.pack('!H', l) + wire
_net_write(s, tcpmsg, expiration)
done = False
soa_rrset = None
soa_count = 0
if relativize:
origin = zone
oname = dns.name.empty
else:
origin = None
oname = zone
tsig_ctx = None
first = True
check_count = 0
while not done:
check_count += 1
if check_count > 5000:
print >>sys.stderr, 'DNS LOOP? dns.query.xfr loop has run %d times' % check_count
mexpiration = _compute_expiration(timeout)
if mexpiration is None or mexpiration > expiration:
mexpiration = expiration
ldata = _net_read(s, 2, mexpiration)
(l,) = struct.unpack('!H', ldata)
wire = _net_read(s, l, mexpiration)
r = dns.message.from_wire(wire, keyring = q.keyring, request_mac = q.mac, xfr = True, origin = origin, tsig_ctx = tsig_ctx, multi = True, first = first)
tsig_ctx = r.tsig_ctx
first = False
answer_index = 0
delete_mode = False
expecting_SOA = False
if soa_rrset is None:
if not (r.answer) or r.answer[0].name != oname:
raise dns.exception.FormError
rrset = r.answer[0]
if rrset.rdtype != dns.rdatatype.SOA:
raise dns.exception.FormError, 'first RRset is not an SOA'
answer_index = 1
soa_rrset = rrset.copy()
if rdtype == dns.rdatatype.IXFR:
if soa_rrset[0].serial == serial:
done = True
else:
expecting_SOA = True
for rrset in r.answer[answer_index:]:
if done:
raise dns.exception.FormError, 'answers after final SOA'
if rrset.rdtype == dns.rdatatype.SOA and rrset.name == oname:
if expecting_SOA:
if rrset[0].serial != serial:
raise dns.exception.FormError, 'IXFR base serial mismatch'
expecting_SOA = False
elif rdtype == dns.rdatatype.IXFR:
delete_mode = not delete_mode
if rrset == soa_rrset and not delete_mode:
done = True
not delete_mode
if expecting_SOA:
rdtype = dns.rdatatype.AXFR
expecting_SOA = False
continue
if done and q.keyring and not (r.had_tsig):
raise dns.exception.FormError, 'missing TSIG'
yield r
s.close()